class Solution:
    def findNumberIn2DArray(self, matrix: List[List[int]], target: int) -> bool:
        if len(matrix)==0 or len(matrix[0])==0:
            return False
        nrow=len(matrix)
        ncol=len(matrix[0])
        x=0
        y=ncol-1
        while x<nrow and y>=0:
            if target==matrix[x][y]:
                return True
            elif target>matrix[x][y]:
                x+=1
            elif target<matrix[x][y]:
                y-=1
        return False